/*******************************************************************************
 * Copyright (c) Jonathan Buck - jonbuck16@gmail.com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    jonbuck16@gmail.com - initial API and implementation
 *******************************************************************************/
package net.jonbuck.tassoo.ui.preference.provider;

import org.eclipse.emf.edit.provider.IItemFontProvider;
import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.IFontProvider;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;

/**
 * 
 * 
 * @since 1.0.0
 */
public class TableDecoratingLabelProvider extends DecoratingLabelProvider implements ITableLabelProvider {

	private ITableLabelProvider provider;

	private ILabelDecorator decorator;

	public TableDecoratingLabelProvider(ILabelProvider provider, ILabelDecorator decorator) {
		super(provider, decorator);
		this.provider = (ITableLabelProvider) provider;
		this.decorator = decorator;
	}

	/**
	 * 
	 */
	public Image getColumnImage(Object element, int columnIndex) {
		Image image = provider.getColumnImage(element, columnIndex);
		if (decorator != null) {
			Image decorated = decorator.decorateImage(image, element);
			if (decorated != null) {
				return decorated;
			}
		}
		return image;

	}

	/**
	 * 
	 */
	public Font getFont(Object element) {
		if (provider instanceof IItemFontProvider) {
			return ((IFontProvider) provider).getFont(element);
		}
		return null;
	}

	/**
	 * 
	 */
	public String getColumnText(Object element, int columnIndex) {
		String text = provider.getColumnText(element, columnIndex);
		if (decorator != null) {
			String decorated = decorator.decorateText(text, element);
			if (decorated != null) {
				return decorated;
			}
		}
		return text;

	}

}
